<?
if($_SESSION['is_admin_login'] == 1) {    
    header( 'Location:' . fwUrl("admin/manage"));
}
?>
<? require_once 'page/__header.php'; ?>
<div id="dvLoginContainer" class="shadowMe">
        
    <input type="hidden" id="secret" value="<?=rand(10000000, 99999990);?><?=rand(10000000, 99999990);?><?=rand(10000000, 99999990);?>" />
    
    <input id="txtUsername" type="text" placeholder="" style="float: left;" disabled="true" value="<?=rand(10000000, 99999990);?>"/>
    <input id="txtPassword" type="password" placeholder="Password"  style="float: right;"/>
    
    <div id="btnLogin"></div>
    <div id="dvLoginErrorMessage" class="hideMe"></div>
        
</div>
<script language="JavaScript" type="text/javascript">
    
    $(document).ready(function(){
        $("#txtUsername").focus();
        
        $("#btnLogin").hover(function(){
            $(this).css("background-image", "url('<?=$sys['host']?>/img/youtube_active.png')"); 
        }, function(){
            $(this).css("background-image", "url('<?=$sys['host']?>/img/youtube_dark.png')");
        }).mousedown(function(){
            $(this).css("top","-2px");          
        }).mouseup(function(){
            $(this).css("top","-3px");          
        }).mouseleave(function(){
            $(this).css("top","-3px");
        }).click(function(){
            do__login();
        });
        
        
        $("#txtUsername, #txtPassword").keydown(function(){
            $("#dvLoginErrorMessage").fadeOut();
        });
            
        pageHeight = Math.round($(document).height() / 2) - 40;     
        $("#dvLoginContainer").css("top", pageHeight + "px");
        
    });
    
    $('input').keypress(function(e){
        if(e.which == 13){          
            do__login();            
            return false;
        }
    }); 
    
    function do__login() {
        $("#dvLoginErrorMessage").fadeOut(100);
        
        if(!fn__validateLoginForm())
            return;
        
        var url = "<?=getPage("doadminlogin")?>";
        
        data = {
            "secret" : $("#secret").val(),
            "u" : $("#txtUsername").val(),
            "p" : $("#txtPassword").val()
        };
        
        $.post(url, data, function(json) {          
            if(json.result && json.result == 1){
                window.setTimeout("location.reload(true)", 300);                
            } else {
                $("#dvLoginErrorMessage").text("Wrong username/password.");
                $("#dvLoginErrorMessage").fadeIn();
            }
        }, "json");
    }
    
    function fn__validateLoginForm() {
        if(!$("#txtUsername").val() || !$("#txtPassword").val()) {
            $("#dvLoginErrorMessage").text("Please input username/password.");
            $("#dvLoginErrorMessage").fadeIn();
            return false;
        } else {
            $("#dvLoginErrorMessage").text("");
            $("#dvLoginErrorMessage").fadeOut(100);
            return true;
        }           
    }
    
</script>
<? require_once 'page/__footer.php'; ?>